# Maintainer: Sarah Ottinger

_realname=service_identity
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=18.1.0
pkgrel=1
pkgdesc='Making it easy to write async iterators (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://service-identity.readthedocs.io/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-attrs" "${MINGW_PACKAGE_PREFIX}-python-idna" "${MINGW_PACKAGE_PREFIX}-python-pyasn1-modules")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest" "${MINGW_PACKAGE_PREFIX}-python-cryptography")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-python-sphinx")
source=("https://github.com/pyca/service_identity/archive/${pkgver}.tar.gz")
sha256sums=('695df7b4ffe00e232ac3887ed347615611d0a9c74074f8832c7eb191f70d2c40')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname//_/-}-$pkgver" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
  ${MINGW_PREFIX}/bin/sphinx-build -b text docs docs/_build/text
  ${MINGW_PREFIX}/bin/sphinx-build -b man docs docs/_build/man
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH=src ${MINGW_PREFIX}/bin/py.test
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm 644 README.rst -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
  install -Dm 644 docs/_build/text/*.txt -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
  install -Dm 644 docs/_build/man/service_identity.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/service_identity.1"
}
